package algebra.rewriting.kfree;

import java.util.HashSet;
import java.util.Set;

import kb.DescriptionLogicsKB;

import entities.concept.Concept;

import utils.exception.SyntaxParsingException;
import utils.io.KBAccess;
import utils.parser.Creator;
import utils.parser.Parser;
import algebra.op.PrimaryOP;
import algebra.op.ProjectionOP;
import algebra.op.SelectionOP;
import algebra.query.pd.ProjDesc;

public class testKFree {

	/**
	 * @param args
	 * @throws SyntaxParsingException 
	 */
	public static void main(String[] args) throws SyntaxParsingException {
		String file = "testkb.kb";
		DescriptionLogicsKB kb = KBAccess.loadKB(file);
		Set<String> cons =new HashSet<String>();
		cons.add("1");
		cons.add("2");
		cons.add("3");
		cons.add("4");
		String spd1 = "(pd-and (pd-concept (and A B) ) (pd-role R (pd-and (pd-feature f) (pd-feature g) )) )";
		String spd2 = "(pd-and  (pd-role R (pd-and (pd-feature g) (pd-and (pd-feature f) (pd-feature h)))) (pd-concept A) )";
		String cs1 = "(exists (role R) (and (<= (role f) 1) (not (< (role f) 1)) ))";
		Concept c1 = Parser.conParser(
				Parser.getListOfTokensFromTokenizer(cs1), kb);
		ProjDesc pd1 = Creator.getPdFromString(spd1, kb);
		ProjDesc pd2 = Creator.getPdFromString(spd2, kb);
		KFreeRewriting.setConstants(cons);
		ProjectionOP pp1 = new ProjectionOP(pd1, new PrimaryOP(kb), kb);
		ProjectionOP pp2 = new ProjectionOP(pd2, new PrimaryOP(kb), kb);
		SelectionOP sp = new SelectionOP(pp1, c1, null);
		double start = System.currentTimeMillis();
		ProjectionOP pp = new ProjectionOP(pd1, pp2, kb);
		boolean res = KFreeRewriting.KFreeOP(pp);
		System.err.println("Free: "+res+"; runtime: "+ (System.currentTimeMillis() - start) / 1000);
	}

}
